package com.ysd.controller;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ysd.entity.User;
import com.ysd.service.userService;
import com.ysd.util.TokenUtil;
/**
 * 后台登录
 * @author CJP
 *
 */
@RestController
public class loginController {
	@Autowired
	userService use;
	@RequestMapping("/loginn")
	public  Map<String, Object> login(String uloginname,String upassword) {
		System.out.println(uloginname);
		System.out.println(upassword);
		Map<String, Object> map=new HashMap<>();
	User u=	use.findByadmin(uloginname, upassword);
	String token=null;
	System.out.println(u);
	if(u!=null) { 
		if(u.getUislockout().equals("是")) {//锁定值里面是时，则提示用户已锁定
		map.put("res", "1");
			return  map;
		}else {
			try {
				token=TokenUtil.sign(u, 1*60*60*1000);
			} catch (UnsupportedEncodingException | JsonProcessingException e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			map.put("token", token);
			map.put("LoginName", u.getUloginname());
			map.put("userid", u.getUid());
			map.put("res", "2");
			map.put("rolesName", u.getRlist());
			return map;
		}
	}
			map.put("res", "3");
		return map;
		
	}

	
	
}
